package com.kauidao.manageweb.controller.dictionary;

import com.kauidao.manageweb.feign.dictionary.DictionaryFeignClient;
import com.kuaidao.common.entity.IdEntity;
import com.kuaidao.common.entity.IdsEntity;
import com.kuaidao.common.entity.JSONResult;
import com.kuaidao.common.entity.PageBean;
import com.kuaidao.sys.dto.dictionary.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Controller
@RequestMapping("/dictionary/Dictionary")
@Slf4j
public class DictionaryController {


    @RequestMapping("/diclistPage")
    public String listPage(){

        log.info("----------------------------------------跳转到列表页面------------------------------------------------");
        return "dictionary/diclistPage";
    }

    @Autowired
    private DictionaryFeignClient dictionaryFeignClient;

    /**
     * 添加字典主题
     * @param dictionaryAddUpdateDTO
     * @return
     */
    @ResponseBody
    @PostMapping("/saveDictionary")
    public JSONResult insertDictionary(@RequestBody DictionaryAddUpdateDTO dictionaryAddUpdateDTO){
        return dictionaryFeignClient.insertDictiondrt(dictionaryAddUpdateDTO);
    }

    /**
     * 根据ID查询字典主题
     * @param
     * @return
     */

    @ResponseBody
    @RequestMapping("/findByPrimaryKey")
    public JSONResult<DictionaryResDTO> findByPrimaryKey(@RequestBody IdEntity idEntity){
        return   dictionaryFeignClient.findDictionaryByPrimaryKey(idEntity);

    }

    /**
     * 分页模糊查询字典主题
     * @param dictionaryReqDTO
     * @return
     */
    @ResponseBody
    @PostMapping("/queryDictionary")
    public JSONResult<PageBean<DictionaryResDTO>> findDictionaryByPage(@RequestBody DictionaryReqDTO dictionaryReqDTO){
        JSONResult<PageBean<DictionaryResDTO>> dictionaryByPage = dictionaryFeignClient.findDictionaryByPage(dictionaryReqDTO);
        return dictionaryByPage;
    }



    /**
     * 根据ID更新字典主题
     * @param dictionaryAddUpdateDTO
     * @return
     */
    @ResponseBody
    @PostMapping("/updateDictionary")
    public JSONResult updateDictionary(@RequestBody DictionaryAddUpdateDTO dictionaryAddUpdateDTO){
        return dictionaryFeignClient.updateDictionary(dictionaryAddUpdateDTO);
    }

    /**
     * 根据IDS删除字典主题 和对应的词条
     * @param idsEntity
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteDictionarys")
    public JSONResult deleteDictionarys(@RequestBody IdsEntity idsEntity){
        return dictionaryFeignClient.deleteDictionarys(idsEntity);
    }


}
